package com.onesports.intelligent.k12.polarlight.controller.common;

import com.onesports.intelligent.k12.polarlight.annotation.UID;
import com.onesports.intelligent.k12.polarlight.common.utils.ResultUtil;
import com.onesports.intelligent.k12.polarlight.domain.dto.common.PwdDTO;
import com.onesports.intelligent.k12.polarlight.domain.dto.sys.CampusDTO;
import com.onesports.intelligent.k12.polarlight.domain.vo.common.AuthTreeVO;
import com.onesports.intelligent.k12.polarlight.security.SecurityUtils;
import com.onesports.intelligent.k12.polarlight.service.sys.AccountService;
import com.onesports.intelligent.k12.polarlight.service.sys.MenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Wsy
 **/
@Api(tags = "用户相关公共API")
@RestController
@RequestMapping("/account-relative")
@RequiredArgsConstructor
public class AccountRelativeController {

    private final AccountService accountService;
    private final MenuService menuService;

    /**
     * 首次登录更改密码
     *
     * @return ResponseEntity<String>
     */
    @PostMapping("/update-pwd")
    @ApiOperation("首次登录更改密码")
    public ResponseEntity<String> updatePwd(@RequestBody PwdDTO dto) {
        this.accountService.firstUpdatePwd(dto, SecurityUtils.getAccountId());
        return ResultUtil.success("操作成功!");
    }

    @ApiOperation("用户系统菜单权限树")
    @GetMapping("/auth-menu-tree-platform")
    @PreAuthorize("isAuthenticated()")
    public ResponseEntity<List<AuthTreeVO>> getAuthMenuTree() {
        String systemCode = SecurityUtils.getSystemCode();
        return ResultUtil.success(this.menuService.getAuthMenuTree(SecurityUtils.getAccountId(), systemCode));
    }
}
